package com.mbti.youmore.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mbti.youmore.entity.Personality;
import com.mbti.youmore.mapper.PersonalityMapper;
import com.mbti.youmore.service.PersonalityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author Guqier
 * @description 针对表【t_personality】的数据库操作Service实现
 * @createDate 2024-05-08 20:30:45
 */
@Service
public class PersonalityServiceImpl extends ServiceImpl<PersonalityMapper, Personality>
        implements PersonalityService{
    @Autowired
    private PersonalityMapper personalityMapper; // 使用Spring自动注入工具类
    public String selectBypersonality(Integer id){
        Personality a = personalityMapper.selectById(id);
        if(a == null){
            return null;
        }
        return a.getExplaining();
    }

    /**
     * 通过角色id获取人格标签
     * @param id 角色id
     * @return 人格标签
     */
    public String selectByroleId(Integer id){
        Personality a = personalityMapper.selectById(id);
        if(a == null){
            System.out.println("成功获取");
            return null;
        }
        return a.getPersonality();
    }

    /**
     * 通过人格标签获取角色id
     * @param personality 人格标签
     * @return 角色id
     */
    public int selectIdBypersonality(String personality){

        Personality a = personalityMapper.selectOne(new LambdaQueryWrapper<Personality>().eq(Personality::getPersonality, personality));
        if(a == null){
            return 0;
        }
        return a.getId();
    }

    public String selectmbtiPic(Integer id){
        Personality a = personalityMapper.selectById(id);
        if(a == null){
            return null;
        }
        return a.getMbtiPicture();
    }
}








